from scavenger import Scavenger
from time import sleep, time
from threading import Thread

class Worker(Thread):
    def __init__(self, daemon, x, y):
        super(Worker, self).__init__()
        self._daemon = daemon
        self._x = x
        self._y = y

    def run(self):
        print self._daemon.scavenge('daimi.test.heavy', {'x':self._x, 'y':self._y}, """
def perform(x, y):
    z = 0.0
    for _x in range(0, x):
        for _y in range(0, y):
            z += (_x * _y) / 1000.0
    return z
""")

s = Scavenger()
sleep(2)

worker1 = Worker(s, 3000, 30000)
worker2 = Worker(s, 3000, 30000)

start = time()

worker1.start()
worker2.start()

worker1.join()
worker2.join()

end = time()

print end - start

s.shutdown()
